//
//  NKDrawBrokenLeftView.swift
//  Nokia
//
//  Created by 易先生 on 2022/4/2.
//

import UIKit
import MYModule

class HeartRateChartVerticalView: View {

    public var verticals : [String] = []{
        didSet{
            drawBrokenVerticalMin(datas: verticals)
        }
    }
    
    public var textColor : UIColor = UIColor.assist_D0D0D0
    
    public var textFont : UIFont = .systemFont(ofSize: 10)


    override func makeUI() {
        super.makeUI()
        
        stackView.axis = .vertical
        stackView.distribution = .equalSpacing
        stackView.alignment = .trailing
       
        self.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    

    override func layoutSubviews() {
        super.layoutSubviews()
        if verticals.count > 0 {
            drawBrokenVerticalMin(datas: verticals)
        }
    }
    
    private lazy var stackView: StackView = {
        let stackView = StackView()
        return stackView
    }()
    

    /// 垂直方向绘制lable
    /// - Parameter datas: 数据源
    public func drawBrokenVerticalMin(datas:[String]) {
        
        var count = datas.count
        if datas.count < 2 {
            count = 1
        }
        
        stackView.arrangedSubviews.forEach {
            stackView.removeArrangedSubview($0)
        }
        stackView.removeAllSubViews()
 
        for min in datas {
            let minLabel = UILabel()
            minLabel.text = min
            minLabel.textColor = textColor
            minLabel.font = textFont
            minLabel.textAlignment = .right
            stackView.addArrangedSubview(minLabel)
            
        }
    }
}
